package net.zjitc.search;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created by Administrator on 2017/6/8.
 */
public class Demo {
    public static void main(String[] args) {
        Set<String> ts=new TreeSet<>(new StringLengthComparator());


        ts.add("abcd");
        ts.add("cc");
        ts.add("cba");
        ts.add("aaa");
        ts.add("z");
        ts.add("hahaha");

            System.out.println(ts);

    }
    static class StringLengthComparator implements Comparator {
        public int compare(Object o1,Object o2){
            String s1 = (String) o1;
            String s2 = (String) o2;
           int temp= s1.length()-s2.length();
           return temp==0?s1.compareTo(s2):temp;
        }
    }
}
